package marlon.smsbatcheditor.activity;

import marlon.smsbatcheditor.Constants;
import marlon.smsbatcheditor.R;
import marlon.smsbatcheditor.db.SmsDAO;
import marlon.smsbatcheditor.model.Sms;
import marlon.smsbatcheditor.utils.DateUtils;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

/**
 * 
 * @author marlonyao<yaolei135@gmail.com>
 */
public class SMSDetailActivity extends Activity implements OnClickListener {
	private TextView tvAddress;
	private TextView tvTime;
	private TextView tvBody;
	private TextView btnCancel;
	
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.sms_detail);
	    
	    Intent intent = getIntent();
	    long smsId = intent.getLongExtra("sms_id", -1);
	    Log.d(Constants.TAG, "smsId is " + smsId);
	    
	    
	    tvAddress = (TextView) findViewById(R.id.tvAddress);
	    tvTime = (TextView) findViewById(R.id.tvTime);
	    tvBody = (TextView) findViewById(R.id.tvBody);
	    btnCancel = (Button) findViewById(R.id.btnCancel);
	    
	    SmsDAO smsDAO = new SmsDAO(this);
	    Sms sms = smsDAO.findById(smsId);
	    tvAddress.setText(sms.getAddress());
	    tvTime.setText(DateUtils.getLongDateTimeString(sms.getDate()));
	    tvBody.setText(sms.getBody());
	    
	    btnCancel.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		this.finish();
	}
}
